home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_ciel_client_network.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  19.6 KB  |  947 lines

  1. unit ntc_ciel_client_network;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     Mask,
  37.     Buttons,
  38.     ExtCtrls,
  39.     inifiles,
  40.  
  41.     IdBaseComponent,
  42.     IdComponent,
  43.     IdTCPConnection,
  44.     IdTCPClient,
  45.     idglobal,
  46.  
  47.     ntc_ciel_client_form;
  48.  
  49. const
  50.     { timeout intervals }
  51.     response_timeout=2000;
  52.     read_timeout=IdTimeoutInfinite;
  53.     read_fail_count=2000;
  54.     connect_timeout=1500;
  55.     max_buffer_size=240;
  56.     crlf=chr(13)+chr(10);
  57.  
  58. type
  59.     response_type_set=(
  60.         exit_ok,
  61.         exit_fail,
  62.         exit_busy,
  63.         exit_wait,
  64.         exit_ready);
  65.     response_type=set of response_type_set;
  66.  
  67.     tscope_network = class(tform)
  68.         network_panel: TPanel;
  69.         server_connect_group: TGroupBox;
  70.         connect_to_server_button: TSpeedButton;
  71.         disconnect_from_server_button: TSpeedButton;
  72.         connected_light: TMaskEdit;
  73.         server_ip_edit: TEdit;
  74.         edit_port: TEdit;
  75.         network_timer: TTimer;
  76.         scope_client: TIdTCPClient;
  77.     status_log: TMemo;
  78.         clear_log_button: TBitBtn;
  79.         messages_button: TBitBtn;
  80.         disk_button: TBitBtn;
  81.  
  82.         { form functions }
  83.         procedure formcreate(
  84.             Sender:TObject);
  85.  
  86.         procedure kill;
  87.  
  88.         procedure form_close_query(
  89.                     Sender: TObject;
  90.             var CanClose: Boolean);
  91.  
  92.         { network controls }
  93.         procedure connect_to_server;
  94.  
  95.         procedure close_network_connection;
  96.  
  97.         procedure connect_to_server_buttonClick(
  98.             Sender: TObject);
  99.  
  100.         function send_message(
  101.             message_string,
  102.             error_string:string)
  103.             :response_type;
  104.  
  105.         function send_request(
  106.             message_str,
  107.             error_str:string)
  108.             :response_type;
  109.  
  110.         function send_request_check(
  111.             message_string:string)
  112.             :response_type;
  113.  
  114.         function get_option_value(
  115.             option:string)
  116.             :string;
  117.  
  118.         function get_float(
  119.                     option:string;
  120.             var exit_result:double)
  121.             :boolean;
  122.  
  123.         function get_integer(
  124.                     option:string;
  125.             var exit_result:longint)
  126.             :boolean;
  127.  
  128.         function get_string(
  129.                     option:string;
  130.             var exit_result:string)
  131.             :boolean;
  132.  
  133.         function get_boolean(
  134.                     option:string;
  135.             var exit_result:boolean)
  136.             :boolean;
  137.  
  138.         procedure network_timerTimer(
  139.             Sender: TObject);
  140.  
  141.         procedure enable_network_timer(
  142.             timeout_interval:longint);
  143.  
  144.         procedure disconnect_from_server_buttonClick(
  145.             Sender: TObject);
  146.  
  147.         { network events }
  148.         procedure update_model_type;
  149.  
  150.         { logging }
  151.         procedure write_status_log(
  152.             e:string;
  153.             message_logging:boolean);
  154.  
  155.         procedure write_status_log_check(
  156.             e:string);
  157.  
  158.         Procedure close_log;
  159.  
  160.         Procedure write_log(
  161.             e:string);
  162.  
  163.         Procedure init_log_file(
  164.             s:string);
  165.  
  166.         { configuration }
  167.         procedure load_settings;
  168.         procedure save_settings;
  169.  
  170.         { events }
  171.         procedure FormShow(
  172.             Sender: TObject);
  173.  
  174.         procedure adjust;
  175.  
  176.         procedure hide_form;
  177.         procedure show_form;
  178.  
  179.         procedure check_activate(
  180.             Sender: TObject);
  181.  
  182.         procedure disk_buttonClick(
  183.             Sender: TObject);
  184.  
  185.         procedure messages_buttonClick(
  186.             Sender: TObject);
  187.  
  188.         procedure clear_log_buttonClick(
  189.             Sender: TObject);
  190.  
  191.     private
  192.         { Private declarations }
  193.         server_ip_address:string;
  194.         received_text:widestring;
  195.         network_connected,
  196.         server_playing,
  197.         network_timed_out:boolean;
  198.         option_names,
  199.         option_values:tstrings;
  200.         indented:integer;
  201.         { logging }
  202.         log_handle:textfile;
  203.         log_filename:string;
  204.         last_line_indented,
  205.         last_line_unindented:boolean;
  206.     public
  207.         { Public declarations }
  208.         network_enabled,
  209.         scope_connected:boolean;
  210.         form_top,
  211.         form_left:integer;
  212.         { logging }
  213.         logging:boolean;
  214.         message_logging:boolean;
  215.         { configuration }
  216.         dimensions:dimensions_record;
  217.  
  218.         { methods }
  219.         procedure check_visible_and_show_hide(
  220.             sender:tobject);
  221.  
  222.         function connected
  223.             :boolean;
  224.     end;
  225.  
  226. var
  227.     scope_network: tscope_network;
  228.  
  229. implementation
  230.  
  231. uses
  232.     ntc_ciel_client_control,
  233.     ntc_ciel_client_info;
  234.  
  235. {$R *.dfm}
  236.  
  237.     { ----------
  238.         form stuff
  239.         ---------- }
  240.  
  241. procedure tscope_network.formcreate(
  242.     Sender:TObject);
  243. begin
  244.     network_timer.enabled:=false;
  245.     { network defaults }
  246.     network_connected:=false;
  247.     server_playing:=false;
  248.     option_names:=tstringlist.create;
  249.     option_values:=tstringlist.create;
  250.     scope_connected:=false;
  251.     connect_to_server_button.enabled:=true;
  252.     server_connect_group.enabled:=true;
  253.     indented:=0;
  254.     last_line_indented:=false;
  255.     last_line_unindented:=false;
  256.     load_settings;
  257.     if logging then
  258.         scope_network.init_log_file('ntc-client.log');
  259.     visible:=false;
  260. end;
  261.  
  262. procedure tscope_network.kill;
  263. begin
  264.     if network_enabled then
  265.         begin
  266.             if scope_connected then
  267.                 begin
  268.                     send_request_check('disconnect');
  269.                     scope_network.scope_connected:=false;
  270.                     send_request_check('bored');
  271.                 end;
  272.             close_network_connection;
  273.         end;
  274.     option_names.free;
  275.     option_values.free;
  276. end;
  277.  
  278. procedure Tscope_network.form_close_query(
  279.             Sender: TObject;
  280.     var CanClose: Boolean);
  281. begin
  282.     visible:=false;
  283.     with dimensions do
  284.         begin
  285.             form_top:=top;
  286.             form_left:=left;
  287.         end;
  288.     if ciel_closing then
  289.         canclose:=true
  290.     else
  291.         canclose:=false;
  292. end;
  293.  
  294.     { -------------
  295.         network stuff
  296.         ------------- }
  297.  
  298. function tscope_network.connected
  299.     :boolean;
  300. begin
  301.     result:=scope_client.connected;
  302. end;
  303.  
  304. procedure tscope_network.connect_to_server;
  305. var
  306.     j,k:integer;
  307.     e:string;
  308.     f:boolean;
  309. begin
  310.     write_status_log_check('connect to server >>');
  311.     e:='connected to server';
  312.     f:=false;
  313.     with scope_client do
  314.         begin
  315.             Port:=StrToint(edit_Port.Text);
  316.             if port<1024 then
  317.                 begin
  318.                     e:='I needs a port greater than 1024';
  319.                     f:=true;
  320.                 end
  321.             else
  322.                 begin
  323.                     server_ip_address:=server_ip_edit.text;
  324.                     host:=server_ip_address;
  325.                     enable_network_timer(connect_timeout);
  326.                     try
  327.                         j:=0;
  328.                         k:=1;
  329.                         connect;
  330.                         repeat
  331.                             application.processmessages;
  332.                             connected_light.color:=$00ff0000+j;
  333.                             if Focused then
  334.                                 connected_light.show;
  335.                             inc(j,k);
  336.                             if j>255 then
  337.                                 k:=-1
  338.                             else if j<0 then
  339.                                 k:=1;
  340.                         until connected or network_timed_out;
  341.                     except
  342.                         on err:exception do
  343.                             begin
  344.                                 e:='exception when trying to connect to server : '+err.message;
  345.                                 f:=true;
  346.                             end;
  347.                     end;
  348.                     if network_timed_out then
  349.                         begin
  350.                             e:='network connection timed out';
  351.                             f:=true;
  352.                             network_timed_out:=false;
  353.                         end
  354.                     else
  355.                         begin
  356.                             network_enabled:=true;
  357.                             if send_request('play','Server wont play')>=[exit_ok] then
  358.                                 begin
  359.                                     connected_light.Color:=cllime;
  360.                                     if Focused then
  361.                                         connected_light.Show;
  362.                                     connect_to_server_button.Enabled:=false;
  363.                                     disconnect_from_server_button.enabled:=true;
  364.                                     get_integer('model',k);
  365.                                     scope_type:=k;
  366.                                     update_model_type;
  367.                                     scope_control.connect_group.enabled:=true;
  368.                                 end;
  369.                         end;
  370.                 end;
  371.         end;
  372.     if f then
  373.         begin
  374.             connect_to_server_button.Enabled:=true;
  375.             disconnect_from_server_button.enabled:=false;
  376.             connected_light.Color:=clred;
  377.             if Focused then
  378.                 connected_light.Show;
  379.             write_status_log_check(e);
  380.         end;
  381.     write_status_log_check('<< connect to server');
  382. end;
  383.  
  384. procedure tscope_network.close_network_connection;
  385. begin
  386.     if scope_connected then
  387.         begin
  388.             send_request_check('disconnect');
  389.             scope_network.scope_connected:=false;
  390.             send_request_check('bored');
  391.         end;
  392.     if scope_client.connected then
  393.         scope_client.Disconnect;
  394.     network_enabled:=false;
  395.     connected_light.Color:=clred;
  396.     if Focused then
  397.         connected_light.Show;
  398.     disconnect_from_server_button.enabled:=false;
  399.     connect_to_server_button.enabled:=true;
  400.     scope_control.change_panel(false);
  401.     scope_control.connect_group.enabled:=false;
  402. end;
  403.  
  404. function tscope_network.send_message(
  405.     message_string,
  406.     error_string:string)
  407.     :response_type;
  408. var
  409.     e,s,t:string;
  410.     done,
  411.     failed:boolean;
  412.     i:integer;
  413.  
  414.     function send
  415.         :response_type;
  416.     begin
  417.         write_status_log_check('send : >>');
  418.         result:=[exit_ok];
  419.         e:='i said '+message_string;
  420.         failed:=false;
  421.         if scope_client.connected then
  422.             begin
  423.                 message_string:=message_string;
  424.                 received_text:='';
  425.                 enable_network_timer(response_timeout);
  426.                 scope_client.writeln(message_string);
  427.                 repeat
  428.                     try
  429.                         application.processmessages;
  430.                         received_text:=scope_client.readln(
  431.                             crlf,read_fail_count,max_buffer_size);
  432.                     except
  433.                         on err:exception do
  434.                             begin
  435.                                 e:=e+' : but failed with : '+err.message;
  436.                                 scope_connected:=false;
  437.                                 connect_to_server_button.Enabled:=true;
  438.                                 disconnect_from_server_button.enabled:=false;
  439.                                 connected_light.Color:=clred;
  440.                                 if Focused then
  441.                                     connected_light.Show;
  442.                                 scope_client.disconnect;
  443.                                 failed:=true;
  444.                             end;
  445.                     end
  446.                 until network_timed_out or (received_text<>'') or failed;
  447.                 s:=trim(received_text);
  448.                 if network_timed_out or failed or (s='') then
  449.                     begin
  450.                         if network_timed_out then
  451.                             begin
  452.                                 e:=e+' : but timed out : ';
  453.                                 failed:=true;
  454.                                 network_timed_out:=false;
  455.                             end;
  456.                     end
  457.                 else if s<>'' then
  458.                     begin
  459.                         if pos('ok',s)=1 then
  460.                             begin
  461.                                 if pos('=',s)=3 then
  462.                                     begin
  463.                                         if pos('(',s)=4 then
  464.                                             begin
  465.                                                 s:=copy(s,5,length(s));
  466.                                                 if s[length(s)]=')' then
  467.                                                     begin
  468.                                                         s[length(s)]:=',';
  469.                                                         option_names.clear;
  470.                                                         option_values.Clear;
  471.                                                         done:=false;
  472.                                                         while not done do
  473.                                                             begin
  474.                                                                 i:=pos(',',s);
  475.                                                                 if i>0 then
  476.                                                                     begin
  477.                                                                         t:=copy(s,1,i-1);
  478.                                                                         s:=copy(s,i+1,length(s));
  479.                                                                         i:=pos('=',t);
  480.                                                                         option_names.Add(copy(t,1,i-1));
  481.                                                                         option_values.add(copy(t,i+1,length(t)));
  482.                                                                     end
  483.                                                                 else
  484.                                                                     done:=true;
  485.                                                             end;
  486.                                                     end
  487.                                                 else
  488.                                                     begin
  489.                                                         e:=e+' : but response incomplete : ';
  490.                                                         failed:=true;
  491.                                                     end;
  492.                                             end
  493.                                     end;
  494.                             end
  495.                         else if pos('fail',s)=1 then
  496.                             begin
  497.                                 e:=e+' : but response incorrect : ';
  498.                                 failed:=true;
  499.                             end
  500.                     end
  501.             end
  502.         else
  503.             begin
  504.                 e:=e+' : not connected, so reseting : ';
  505.                 connect_to_server_button.Enabled:=true;
  506.                 disconnect_from_server_button.enabled:=false;
  507.                 connected_light.Color:=clred;
  508.                 if Focused then
  509.                     connected_light.Show;
  510.                 scope_client.disconnect;
  511.                 failed:=true;
  512.             end;
  513.         if failed then
  514.             begin
  515.                 e:=e+' : '+error_string;
  516.                 with scope_control do
  517.                     begin
  518.                         ignore_event_north:=event_0;
  519.                         ignore_event_south:=event_0;
  520.                         ignore_event_west:=event_0;
  521.                         ignore_event_east:=event_0;
  522.                     end;
  523.                 result:=[exit_fail];
  524.             end;
  525.         write_status_log_check(e);
  526.         write_status_log_check('<< : send');
  527.     end;
  528.  
  529. begin
  530.     result:=send;
  531. end;
  532.  
  533. function tscope_network.send_request(
  534.     message_str,
  535.     error_str:string)
  536.     :response_type;
  537. begin
  538.     result:=send_message(message_str,error_str);
  539. end;
  540.  
  541. function tscope_network.send_request_check(
  542.     message_string:string)
  543.     :response_type;
  544. begin
  545.     result:=send_request(message_string,no_response);
  546. end;
  547.  
  548. function tscope_network.get_option_value(
  549.     option:string)
  550.     :string;
  551. var
  552.     i:integer;
  553. begin
  554.     i:=option_names.indexof(option);
  555.     if i>=0 then
  556.         result:=option_values[i]
  557.     else
  558.         result:='';
  559. end;
  560.  
  561. function tscope_network.get_float(
  562.             option:string;
  563.     var exit_result:double)
  564.     :boolean;
  565. var
  566.     s:string;
  567. begin
  568.     s:=get_option_value(option);
  569.     if s<>'' then
  570.         begin
  571.             exit_result:=strtofloat(s);
  572.             result:=true;
  573.         end
  574.     else
  575.         result:=false;
  576. end;
  577.  
  578. function tscope_network.get_integer(
  579.             option:string;
  580.     var exit_result:longint)
  581.     :boolean;
  582. var
  583.     s:string;
  584. begin
  585.     s:=get_option_value(option);
  586.     if s<>'' then
  587.         begin
  588.             exit_result:=strtoint(s);
  589.             result:=true;
  590.         end
  591.     else
  592.         result:=false;
  593. end;
  594.  
  595. function tscope_network.get_string(
  596.             option:string;
  597.     var exit_result:string)
  598.     :boolean;
  599. var
  600.     s:string;
  601. begin
  602.     s:=get_option_value(option);
  603.     if s<>'' then
  604.         begin
  605.             exit_result:=s;
  606.             result:=true;
  607.         end
  608.     else
  609.         result:=false;
  610. end;
  611.  
  612. function tscope_network.get_boolean(
  613.             option:string;
  614.     var exit_result:boolean)
  615.     :boolean;
  616. var
  617.     s:string;
  618. begin
  619.     s:=get_option_value(option);
  620.     if s<>'' then
  621.         begin
  622.             exit_result:=s='true';
  623.             result:=true;
  624.         end
  625.     else
  626.         result:=false;
  627. end;
  628.  
  629. procedure tscope_network.enable_network_timer(
  630.     timeout_interval:longint);
  631. begin
  632.     with network_timer do
  633.         begin
  634.             enabled:=false;
  635.             network_timed_out:=false;
  636.             interval:=timeout_interval;
  637.             enabled:=true;
  638.         end;
  639. end;
  640.  
  641. procedure tscope_network.network_timerTimer(
  642.     Sender: TObject);
  643. begin
  644.     network_timer.enabled:=false;
  645.     network_timed_out:=true;
  646. end;
  647.  
  648. procedure tscope_network.update_model_type;
  649. begin
  650.     with scope_control do
  651.         slew_group.visible:=true;
  652. end;
  653.  
  654.     { -------
  655.         logging
  656.         ------- }
  657.  
  658. procedure tscope_network.write_status_log(
  659.     e:string;
  660.     message_logging:boolean);
  661. var
  662.     s:string;
  663.     a,m:boolean;
  664. begin
  665.     if message_logging then
  666.         begin
  667.             a:=false;
  668.             m:=false;
  669.             if pos('>>',e)>0 then
  670.                 begin
  671.                     if not last_line_indented then
  672.                         inc(indented,2)
  673.                     else
  674.                         last_line_indented:=false;
  675.                     a:=true;
  676.                 end
  677.             else if pos('<<',e)>0 then
  678.                 begin
  679.                     if not last_line_unindented then
  680.                         dec(indented,2)
  681.                     else
  682.                         last_line_unindented:=false;
  683.                     m:=true;
  684.                 end;
  685.             s:=stringofchar(#32,indented)+e;
  686.             if a then
  687.                 begin
  688.                     inc(indented,2);
  689.                 end
  690.             else if m then
  691.                 begin
  692.                     dec(indented,2);
  693.                 end;
  694.             status_log.Lines.Add(s+#13);
  695.             scope_network.write_log(s);
  696.         end;
  697. end;
  698.  
  699. procedure tscope_network.write_status_log_check(
  700.     e:string);
  701. begin
  702.     if message_logging then
  703.         write_status_log(e,true);
  704. end;
  705.  
  706. Procedure tscope_network.init_log_file(
  707.     s:string);
  708. var
  709.     io:integer;
  710. begin
  711.     try
  712.         log_filename:=application_path+s;
  713.         {$I-}
  714.         assignfile(log_handle,log_filename);
  715.         {$I+}
  716.         io:=ioresult;
  717.         if io=0 then
  718.             begin
  719.                 rewrite(log_handle);
  720.                 writeln(log_handle,DateTimeToStr(now)+' : session started');
  721.                 close_log;
  722.             end
  723.         else
  724.             write_status_log_check('cant create log file : '+log_filename);
  725.     except
  726.         on err:exception do
  727.             begin
  728.                 write_status_log_check('failed to open log : '+err.message);
  729.             end;
  730.     end;
  731. end;
  732.  
  733. Procedure tscope_network.write_log(
  734.     e:string);
  735. var
  736.     io:integer;
  737. begin
  738.     if logging then
  739.         begin
  740.             try
  741.                 {$I-}
  742.                 assignfile(log_handle,log_filename);
  743.                 {$I+}
  744.                 io:=ioresult;
  745.                 if io=0 then
  746.                     begin
  747.                         append(log_handle);
  748.                         writeln(log_handle,FormatDateTime('hh:mm:ss.zzz',now)+' : '+e);
  749.                         close_log;
  750.                     end
  751.                 else
  752.                     write_status_log_check('cant open log : '+log_filename);
  753.             except
  754.                 on err:exception do
  755.                     begin
  756.                         write_status_log_check('failed to write to log : '+err.message);
  757.                         close_log;
  758.                     end
  759.             end;
  760.         end;
  761. end;
  762.  
  763. Procedure tscope_network.close_log;
  764. var
  765.     io:integer;
  766. begin
  767.     try
  768.         {$I-}
  769.         closefile(log_handle);
  770.         {$I+}
  771.         io:=ioresult;
  772.         if io<>0 then
  773.              write_status_log_check(
  774.             'failed to close : '+log_filename+' : '+inttostr(io));
  775.     except
  776.         on err:exception do
  777.             write_status_log_check('failed to close log : '+err.message);
  778.     end;
  779. end;
  780.  
  781.     { -------------
  782.         configuration
  783.         ------------- }
  784.  
  785. procedure tscope_network.load_settings;
  786. begin
  787.     ini_file:=tinifile.create(application_path+'ciel.ini');
  788.     with ini_file do
  789.         begin
  790.             server_ip_address:=ReadString('network','ip_address','127.0.0.1');
  791.             server_ip_edit.text:=server_ip_address;
  792.             logging:=ReadBool('network','logging',false);
  793.             if logging then
  794.                 disk_button.Font.style:=[fsbold]
  795.             else
  796.                 disk_button.font.style:=[];
  797.             message_logging:=ReadBool('network','message_logging',true);
  798.             if message_logging then
  799.                 messages_button.Font.style:=[fsbold]
  800.             else
  801.                 messages_button.font.style:=[];
  802.             { form }
  803.             scope.get_dimensions(scope_network,@dimensions,'network',ini_file);
  804.             left:=dimensions.form_left;
  805.             top:=dimensions.form_top;
  806.             visible:=readbool('network','visible',false);
  807.         end;
  808.     ini_file.free;
  809. end;
  810.  
  811. procedure tscope_network.save_settings;
  812. begin
  813.     with ini_file do
  814.         begin
  815.             writestring('network','ip_address',server_ip_address);
  816.             writebool('network','logging',logging);
  817.             writebool('network','message_logging',message_logging);
  818.             { form }
  819.             scope.find_vdu(scope_network,@dimensions);
  820.             scope.write_dimensions(@dimensions,left,top,'network',ini_file);
  821.             writebool('network','visible',visible);
  822.         end;
  823. end;
  824.  
  825.     { ------
  826.         events
  827.         ------ }
  828.  
  829. procedure tscope_network.FormShow(
  830.     Sender: TObject);
  831. begin
  832.     with dimensions do
  833.         begin
  834.             top:=form_top;
  835.             left:=form_left;
  836.         end;
  837. end;
  838.  
  839. procedure tscope_network.adjust;
  840. begin
  841.     with dimensions do
  842.         begin
  843.             form_top:=trunc(form_top/last_screen_height*current_height);
  844.             form_left:=trunc(form_left/last_screen_width*current_width);
  845.         end;
  846.     if visible then
  847.         show;
  848. end;
  849.  
  850. procedure tscope_network.check_visible_and_show_hide(
  851.     sender:tobject);
  852. begin
  853.     if visible then
  854.         hide_form
  855.     else
  856.         show_form;
  857.     scope.show_hide(sender,visible);
  858. end;
  859.  
  860. procedure tscope_network.hide_form;
  861. begin
  862.     with dimensions do
  863.         begin
  864.             form_top:=top;
  865.             form_left:=left;
  866.         end;
  867.     Visible:=false;
  868.     formstyle:=fsnormal;
  869. end;
  870.  
  871. procedure tscope_network.show_form;
  872. begin
  873.     formstyle:=fsstayontop;
  874.     Visible:=true;
  875. end;
  876.  
  877. procedure Tscope_network.check_activate(
  878.     Sender: TObject);
  879. begin
  880.     scope.form_activate(scope_network,@dimensions);
  881. end;
  882.  
  883. procedure tscope_network.connect_to_server_buttonClick(
  884.     Sender: TObject);
  885. begin
  886.     connect_to_server;
  887. end;
  888.  
  889. procedure tscope_network.disconnect_from_server_buttonClick(
  890.     Sender: TObject);
  891. begin
  892.     if scope_client.connected then
  893.         begin
  894.             if scope_connected then
  895.                 scope_control.disconnect_from_scope;
  896.             send_request('bored','server wont go');
  897.         end;
  898.     close_network_connection;
  899. end;
  900.  
  901. procedure tscope_network.clear_log_buttonClick(
  902.     Sender: TObject);
  903. begin
  904.     status_log.Lines.Clear;
  905.     write_status_log_check('log cleared');
  906. end;
  907.  
  908. procedure tscope_network.messages_buttonClick(
  909.     Sender: TObject);
  910. begin
  911.     if not message_logging then
  912.         begin
  913.             message_logging:=true;
  914.             messages_button.font.style:=[fsbold];
  915.             write_status_log_check('messages enabled');
  916.         end
  917.     else
  918.         begin
  919.             messages_button.font.style:=[];
  920.             write_status_log_check('messages disabled');
  921.             message_logging:=false;
  922.         end;
  923. end;
  924.  
  925. procedure tscope_network.disk_buttonClick(
  926.     Sender: TObject);
  927. begin
  928.     with scope_network do
  929.         begin
  930.             if logging then
  931.                 begin
  932.                     logging:=false;
  933.                     disk_button.font.style:=[];
  934.                     write_status_log_check('logging disabled');
  935.                 end
  936.             else
  937.                 begin
  938.                     logging:=true;
  939.                     init_log_file('ntc-client.log');
  940.                     disk_button.font.style:=[fsbold];
  941.                     write_status_log_check('logging enabled');
  942.                 end;
  943.         end;
  944. end;
  945.  
  946. end.
  947.